home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Online / SpeakFreely / src / lpc10 / placea.c < prev    next >
C/C++ Source or Header  |  2000-05-18  |  4KB  |  145 lines

  1. /************************************************************************
  2. *
  3. *    PLACEA Version 48
  4. *
  5. ************************************************************************/
  6.  
  7. #include "lpcdefs.h"
  8.  
  9. #define lrange (AF-2)*LFRAME + 1
  10. #define hrange AF*LFRAME
  11.  
  12. placea( ipitch, voibuf, obound, vwin, awin, ewin)
  13. int obound;
  14. int ipitch, voibuf[2][AF+1];
  15. int vwin[2][AF], awin[2][AF], ewin[2][AF];
  16. {
  17.  
  18. /* Local variables and parameters    */
  19.  
  20. int i, j, k, l;
  21. short ephase, winv;
  22. static short allv;
  23. int temp;
  24.  
  25. /*   Place the Analysis window based on the voicing window
  26. *   placement, onsets, tentative voicing decision, and pitch.
  27. *
  28. *   Case 1:  Sustained Voiced Speech
  29. *   If the five most recent voicing decisions are 
  30. *   voiced, then the window is placed phase-synchronously with the 
  31. *   previous window, as close to the present voicing window if possible.
  32. *   If onsets bound the voicing window, then preference is given to
  33. *   a phase-synchronous placement which does not overlap these onsets.
  34. *
  35. *   Case 2:  Voiced Transition
  36. *   If at least one voicing decision in AF is voicied, and there are no
  37. *   onsets, then the window is placed as in case 1.
  38. *
  39. *   Case 3:  Unvoiced Speech or Onsets
  40. *   If both voicing decisions in AF are unvoiced, or there are onsets,
  41. *   then the window is placed coincident with the voicing window.
  42. *
  43. *   Note:  During phase-synchronous placement of windows, the length
  44. *   is not altered from MAXWIN, since this would defeat the purpose
  45. *   of phase-synchronous placement.
  46.  
  47. * Check for case 1 and case 2    */
  48.  
  49. allv =            (voibuf[1][AF-2] == 1)?1:0;
  50. allv = (allv && voibuf[0][AF-1] == 1)?1:0;
  51. allv = (allv && voibuf[1][AF-1] == 1)?1:0;
  52. allv = (allv && voibuf[0][AF  ] == 1)?1:0;
  53. allv = (allv && voibuf[1][AF  ] == 1)?1:0;
  54.  
  55. winv = (voibuf[0][AF  ] == 1 ||  voibuf[1][AF  ] == 1)?1:0;
  56.  
  57. if (allv || (winv && (obound == 0))) {
  58.  
  59. /* APHASE:  Phase synchronous window placement.
  60. * Get minimum lower index of the window.        */
  61.  
  62.     i = (lrange + ipitch - 1 - awin[0][AF-2]) / ipitch;
  63.     i = i * ipitch;
  64.     i = i + awin[0][AF-2];
  65.  
  66. /* L = the actual length of this frame's analysis window.    */
  67.  
  68.     l = MAXWIN;
  69.  
  70. /* Calculate the location where a perfectly centered window would start.  */
  71.  
  72.     k = (vwin[0][AF-1] + vwin[1][AF-1] + 1 - l) * 0.5;
  73.  
  74. /* Choose the actual location to be the pitch multiple closest to this.    */
  75.     temp = (float)((float)((float)(k - i) / (float)ipitch) + .5);
  76.     awin[0][AF-1] = i + temp  * ipitch;
  77.     awin[1][AF-1] = awin[0][AF-1] + l - 1;
  78. /* If there is an onset bounding the right of the voicing window and the
  79. * analysis window overlaps that, then move the analysis window backward
  80. * to avoid this onset.    */
  81.  
  82.     if (obound >= 2 && awin[1][AF-1] > vwin[1][AF-1]) {
  83.         awin[0][AF-1] -= ipitch;
  84.         awin[1][AF-1] -= ipitch;
  85.     }
  86.  
  87. /* Similarly for the left of the voicing window.    */
  88.  
  89.     if ((obound == 1 || obound == 3) && awin[0][AF-1] < vwin[0][AF-1]) {
  90.         awin[0][AF-1] += ipitch;
  91.         awin[1][AF-1] += ipitch;
  92.     }
  93.  
  94. /* If this placement puts the analysis window above HRANGE, then
  95. * move it backward an integer number of pitch periods.    */
  96.  
  97.     while (awin[1][AF-1] > hrange)    {
  98.     
  99.         awin[0][AF-1] -= ipitch;
  100.         awin[1][AF-1] -= ipitch;
  101.     }
  102.  
  103. /* Similarly if the placement puts the analysis window below LRANGE.    */
  104.  
  105.     while (awin[0][AF-1] < lrange)    {
  106.         awin[0][AF-1] += ipitch;
  107.         awin[1][AF-1] += ipitch;
  108.     }
  109.  
  110.  
  111. /* Make Energy window be phase-synchronous.    */
  112.  
  113.     ephase = 1;
  114.  
  115. /* Case 3    */
  116. }
  117. else    {
  118.     awin[0][AF-1] = vwin[0][AF-1];
  119.     awin[1][AF-1] = vwin[1][AF-1];
  120.     ephase = 0;
  121. }
  122.  
  123. /* RMS is computed over an integer number of pitch periods in the analysis
  124. * window.  When it is not placed phase-synchronously, it is placed as close 
  125. * as possible to onsets.  */
  126.  
  127. j = ((awin[1][AF-1]-awin[0][AF-1]+1)/ipitch)*ipitch;
  128. if (j == 0 || !winv) {
  129.     ewin[0][AF-1] = vwin[0][AF-1];
  130.     ewin[1][AF-1] = vwin[1][AF-1];
  131. }
  132. else     
  133.     if (!ephase && obound == 2) {
  134.         ewin[0][AF-1] = awin[1][AF-1] - j + 1;
  135.         ewin[1][AF-1] = awin[1][AF-1];
  136.     }
  137.     else    {
  138.         ewin[0][AF-1] = awin[0][AF-1];
  139.         ewin[1][AF-1] = awin[0][AF-1] + j - 1;
  140.     }
  141.  
  142.  
  143.  
  144. }
  145.